package com.njqy.ticket.controller.common;

import com.njqy.ticket.dto.param.LoginParam;
import com.njqy.ticket.service.common.ILoginService;
import com.njqy.ticket.util.R;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Api(tags = "登录接口")
@RestController
public class LoginController {

    @Autowired
    private ILoginService loginService;

    @PostMapping("/login")
    public R login(@RequestBody LoginParam loginParam) {
        if(Objects.isNull(loginParam)){
            return R.failed("参数异常");
        }
        Map<String, Object> result = new HashMap<>();
        result.put("token", loginService.login(loginParam.getName(), loginParam.getPassword()));
        return R.ok(result);
    }

}
